const fs = require("fs");
const config = require("./config");
const handle = require("./handle");
let dao_index = 0;
let mapper_inde = 0;
module.exports = {
  mapper: (name) => {
    let class_name = handle.name.second(handle.name.first(name));
    let file_name = class_name + "Mapper.java";
    fs.writeFile(
      config.file_path + "mapper\\" + file_name,
      `package ${config.package}.mapper;

import org.springframework.stereotype.Component;
import ${config.package}.dao.${class_name};

/**
 * ${class_name}'s Mapper
 *
 * @author Code Generator at ${new Date().toLocaleString()}
 */
@Component
public interface ${class_name}Mapper extends tk.mybatis.mapper.common.Mapper<${class_name}> {
}
`,
      (err) => {
        let message = `mapper第${++mapper_inde}个：${err || "成功"}`;
        if (err) console.error(message);
        else console.info(message);
      }
    );
  },
  dao: (name, content) => {
    let file_name = handle.name.second(handle.name.first(name)) + ".java";
    fs.writeFile(config.file_path + "dao\\" + file_name, content, (err) => {
      let message = `dao第${++dao_index}个：${err || "成功"}`;
      if (err) console.error(message);
      else console.info(message);
    });
  },
};
